<!-- 材料订购作业:蹇泽阳 -->
<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" :formList="formList" @findClicked="findClicked" />
    <Find :OriginalFilter="{ static: true }" :formList="formList2" @findClicked="findClicked2" :searchImg="false" />
    <el-card shadow="never" :body-style="{ padding: '5px 10px 5px' }" class="mt10">
      <div slot="header" class="f16">
        <span style="font-weight: 600">材料订购明细</span>
      </div>
      <Table
        :tableHeader="tableHeader"
        :tableData="tableData"
        selection
        class="mt10"
        :summaryData="summaryData"
        summary
        @currentRow="clickRow"
        :isLoading="isLoading"
        @selectList="selectList1"
        :getTableList="getTableList"
        @confirmChange="confirmChange"
      />
    </el-card>
    <el-card shadow="never" :body-style="{ padding: '5px' }">
      <PageModule :PageData="{ total }" @pageSizeChange="handleSizeChange" @pageChange="handleCurrentChange" />
    </el-card>
    <!-- 选订单材料(正单) -->
    <el-drawer v-model="dialogTableVisible" :direction="'ttb'" size="small" :with-header="false">
      <Find :OriginalFilter="{ static: true }" :formList="formList3" @findClicked="findClicked3" />
      <el-card shadow="never" :body-style="{ padding: '11px 20px' }">
        <Table :tableHeader="tableHeader2" :tableData="tableData2" class="mr55" selection @selectList="selectList2" :isLoading="isLoading2" />
        <PageModule :PageData="{ total: total2, buttonS: true }" @pageSizeChange="handleSizeChange2" @pageChange="handleCurrentChange2" />
      </el-card>
    </el-drawer>
    <!-- 选订单材料(补单) -->
    <el-drawer v-model="dialogTableVisible2" :direction="'ttb'" size="small" :with-header="false">
      <Find :OriginalFilter="{ static: true }" :formList="formList4" @findClicked="findClicked4" />
      <el-card shadow="never" :body-style="{ padding: '11px 20px' }">
        <Table :tableHeader="tableHeader3" :tableData="tableData3" class="mr55" selection @selectList="selectList3" :isLoading="isLoading3" />
        <PageModule :PageData="{ total: total3, buttonS: true }" @pageSizeChange="handleSizeChange3" @pageChange="handleCurrentChange3" />
      </el-card>
    </el-drawer>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
import JMessage from '@/utils/JMessage'
export default defineComponent({
  name: 'MaterialOrdering'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import Find from '@/components/Find/index.vue'
import { selectList, selectSomeList } from '@/plugins/mixin'
import LoginWork from '@/utils/LoginWork'
import fileRequest from '@/utils/fileRequest'
import service from '@/utils/request'
import { ElMessage } from 'element-plus'
import { debounce } from 'lodash'
import { computed, onMounted, watch } from 'vue'
const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '请输入型体',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '底模号',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '厂商代码 厂商名称',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '请输入订购单号',
    inputValue: ''
  },
  {
    type: 'date',
    dateLabel: '订购日期',
    dateValue: ''
  },
  {
    type: 'checkbox',
    checkboxLabel: '未下单',
    checked: true
  },
  {
    type: 'checkbox',
    checkboxLabel: '已下单',
    checked: false
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '查询',
    bgColor: '#1890FF'
  }
]) as any
const formList2 = ref([
  {
    type: 'button',
    checkboxLabel: '选订单材料(正单)'
  },
  {
    type: 'button',
    checkboxLabel: '选订单材料(补单)'
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '厂商代码 厂商名称',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'dateSingle',
    dateLabel: '交期',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '形成订购单'
  },
  {
    type: 'button',
    checkboxLabel: '导出订购单'
  },
  {
    type: 'button',
    checkboxLabel: '置空订购信息'
  },
  {
    type: 'button',
    checkboxLabel: '打勾记录删除'
  }
])

const formList3 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '材料类型',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '请输入材料名称',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '返回'
  },
  {
    type: 'button',
    checkboxLabel: '生成订购资料'
  }
])
const formList4 = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入指令号',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '材料类型',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '请输入材料名称',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '置空',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '查询',
    bgColor: '#1890FF'
  },
  {
    type: 'button',
    checkboxLabel: '返回'
  },
  {
    type: 'button',
    checkboxLabel: '生成订购资料'
  }
])
const tableHeader = ref<any>([
  {
    change: true,
    label: '类型',
    prop: 'type'
  },
  {
    change: true,
    label: '指令',
    prop: 'lotNo',
    width: '160px'
  },
  {
    change: true,
    label: '型体',
    prop: 'style'
  },
  {
    change: true,
    label: '品牌',
    prop: 'brand'
  },
  {
    change: true,
    label: '颜色',
    prop: 'color'
  },
  {
    change: true,
    label: '订单数',
    prop: 'orderQty',
    width: 50
  },
  {
    label: '号码',
    prop: 'sizeNo',
    width: 50
  },
  {
    change: true,
    label: '订购单号',
    prop: 'purNo',
    width: 130
  },
  {
    change: true,
    label: '订购日期',
    prop: 'purDate',
    width: 150
  },
  {
    label: '请购数量',
    prop: 'purQty'
  },
  {
    change: true,
    label: '物料编码',
    prop: 'mtlNo',
    width: 100
  },
  {
    change: true,
    label: '材料颜色',
    prop: 'mtlColor'
  },
  {
    change: true,
    label: '材料名称',
    prop: 'mtlName',
    width: 140
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    width: 50
  },
  {
    change: true,
    label: '单位',
    prop: 'mtlUnit',
    width: 50
  },
  {
    change: true,
    label: '厂商',
    prop: 'vendorName'
  },
  {
    change: true,
    label: '交期',
    prop: 'deliveryDate'
  },
  {
    label: '备注',
    prop: 'remark',
    width: 150
  },
  {
    type: 'select',
    label: '责任人',
    prop: 'dutyUser',
    width: 150
  },
  {
    type: 'select',
    label: '责任原因',
    prop: 'dutyRek',
    width: 200
  }
])

// 表一模块
const currentClickRow = ref()
const clickRow = (row: any = tableData.value[0]) => {
  currentClickRow.value = JSON.parse(JSON.stringify(row))
}
// 置空按钮
const findClicked = async (content: string) => {
  if (content === '置空') {
    formList.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '查询') {
    getTableList()
  }
}
const dialogTableVisible = ref(false)
const dialogTableVisible2 = ref(false)
const currentTime = computed(() => {
  const now = new Date()
  const year = now.getFullYear()
  const month = now.getMonth() + 1 // 月份从0开始，需要加1
  const day = now.getDate()
  const hour = now.getHours()
  const minute = now.getMinutes()
  return `${year}-${month}-${day} ${hour}:${minute}`
})

const findClicked2 = async (content: string) => {
  if (content === '形成订购单') {
    if (selectedLists.value.length === 0) {
      JMessage.warning('请打勾材料订购明细')
      return
    }
    let res = await LoginWork.post<any, any>('/material/createPcOrderMtlOrder', {
      createFlag: 1,
      deliveryDate: formList2.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '交期'
      )?.dateValue,
      list: selectedLists.value.map((item: any) => {
        item.dutyRek = item.dutyRek.selectValue || ''
        item.dutyUser = item.dutyUser.selectValue || ''
        return item
      }),
      vendorName: formList2.value
        .find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称')
        ?.selectValue?.split(' ')[1],
      vendorNo: formList2.value
        .find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称')
        ?.selectValue?.split(' ')[0]
    })
    if (res.code === 200) {
      JMessage.success(res.message)
      tableData.value = res.data.list
    } else {
      JMessage.warning(res.message)
    }
    // formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '已下单').checked = true
    // getTableList()
  }
  if (content === '置空订购信息') {
    if (selectedLists.value.length === 0) {
      JMessage.warning('请打勾材料订购明细')
      return
    }
    let res = await LoginWork.post<any, any>('/material/createPcOrderMtlOrder', {
      createFlag: 2,
      deliveryDate: formList2.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '交期'
      )?.dateValue?.[0],
      list: selectedLists.value.map((item: any) => {
        item.dutyRek = item.dutyRek.selectValue || ''
        item.dutyUser = item.dutyUser.selectValue || ''
        return item
      }),
      vendorName: formList2.value
        .find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称')
        ?.selectValue?.split(' ')[1],
      vendorNo: formList2.value
        .find((item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称')
        ?.selectValue?.split(' ')[0]
    })
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.warning(res.message)
    }
    getTableList()
  }
  if (content === '选订单材料(正单)') {
    dialogTableVisible.value = true
    getTableList2()
  }
  if (content === '选订单材料(补单)') {
    dialogTableVisible2.value = true
    getTableList3()
  }
  if (content === '导出订购单') {
    if (!currentClickRow.value.purNo) {
      JMessage.warning('没有订购单号')
      return
    }
    const res = (await fileRequest.get(`/material/downMtlPurSlipExcel?slipNo=${currentClickRow.value.purNo}`)) as any
    const link = document.createElement('a') // 利用a标签自定义下载文件名
    let blob = new Blob([res.data]) // 创建Blob对象，设置文件类型
    link.style.display = 'none'
    //设置连接
    link.href = window.URL.createObjectURL(blob)
    const FileName = decodeURI(res.headers['content-disposition'].split(`utf-8''`)[1])
    link.download = `${currentClickRow.value.vendorName} ${currentTime.value}.xls` //自定义文件名字
    document.body.appendChild(link)
    //模拟点击事件
    link.click()
    document.body.removeChild(link)
  }
  if (content === '打勾记录删除') {
    if (selectedLists.value.length === 0) {
      JMessage.warning('请打勾材料订购明细')
      return
    }
    let res = await LoginWork.post<any, any>('/material/createPcOrderMtlOrder', {
      createFlag: 4,
      deliveryDate: formList2.value.find(
        (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '交期'
      )?.dateValue?.[0],
      list: selectedLists.value.map((item: any) => {
        item.dutyRek = item.dutyRek.selectValue || ''
        item.dutyUser = item.dutyUser.selectValue || ''
        return item
      }),
      vendorName: '',
      vendorNo: ''
    })
    if (res.code === 200) {
      JMessage.success('打勾记录删除成功')
      getTableList()
    } else {
      JMessage.warning(res.message)
    }
  }
}
const findClicked3 = async (content: string) => {
  if (content === '置空') {
    formList3.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '返回') {
    dialogTableVisible.value = false
  }
  if (content === '生成订购资料') {
    if (selectedLists2.value.length === 0) {
      JMessage.warning('请打勾材料')
      return
    }
    let res = await LoginWork.post<any, any>('/material/pcOrderMtlMakeOrder', {
      list: selectedLists2.value,
      mark: 1
    })
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.warning(res.message)
    }
    dialogTableVisible.value = false
    formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '已下单').checked = false
    getTableList()
  }
}
const findClicked4 = async (content: string) => {
  if (content === '置空') {
    formList4.value.forEach((item: any) => {
      item.inputValue = ''
      item.selectValue = ''
      item.dateValue = ''
    })
  }
  if (content === '返回') {
    dialogTableVisible2.value = false
  }
  if (content === '生成订购资料') {
    if (selectedLists3.value.length === 0) {
      JMessage.warning('请打勾材料')
      return
    }
    let res = await LoginWork.post<any, any>('/material/pcOrderMtlMakeOrder', {
      list: selectedLists3.value,
      mark: 2
    })
    if (res.code === 200) {
      JMessage.success(res.message)
    } else {
      JMessage.warning(res.message)
    }
    dialogTableVisible2.value = false
    formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '已下单').checked = false
    getTableList()
  }
}
const tableData = ref([])
const isLoading = ref(true)
// 总计
interface summaryDataType {
  index: number
  num: number | undefined
}
const summaryData = ref<summaryDataType[]>([
  {
    index: 6,
    num: 0
  },
  {
    index: 10,
    num: 0
  }
])
// 分页器
const currentPage = ref(1)
const pageSize = ref(40)
const total = ref(0)
const handleSizeChange = (val: number) => {
  pageSize.value = val
  getTableList()
}
const handleCurrentChange = (val: number) => {
  currentPage.value = val
  getTableList()
}
// 表格计算函数
const cfmFlag = () => {
  const Unaudited = formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '未下单')
  const Audited = formList.value.find((item: any) => item.type === 'checkbox' && i18n.global.t(item.checkboxLabel) === '已下单')
  if (!Unaudited || !Audited) return
  if (Unaudited.checked && Audited.checked) {
    return '0'
  } else if (Unaudited.checked) {
    return '1'
  } else if (Audited.checked) {
    return '2'
  } else {
    ElMessage('必须至少选择一项')
    Unaudited.checked = true
    Audited.checked = true
    return '0'
  }
}
// 获取表数据
const getTableList = debounce(async () => {
  isLoading.value = true
  let tableDataList = await service.post<any, any>('/material/pcOrderMtlMakeOrderDetail', {
    choose: 0,
    lotNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令号'
    )?.inputValue,
    moldNo: formList.value.find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '底模号')
      ?.selectValue,
    purEndDate: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '订购日期'
    )?.dateValue?.[1],
    purNo: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入订购单号'
    )?.inputValue,
    purStartDate: formList.value.find(
      (item: any) => item.dateLabel && Jzhcn.Find[item.dateLabel.split('.')[1] as keyof typeof Jzhcn.Find] === '订购日期'
    )?.dateValue?.[0],
    style: formList.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入型体'
    )?.inputValue,
    vendorName: formList.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称')
      ?.selectValue?.split(' ')[1],
    pageNum: currentPage.value,
    pageSize: pageSize.value,
    order: cfmFlag() //	有无欠数(Y/N)	string	body	true
  })
  isLoading.value = false
  tableData.value = tableDataList.list.map((item: any) => {
    if (item.purNo === null) {
      item.disable = false
    } else {
      tableHeader.value.find((item: any) => item.label === '号码').disable = true
      tableHeader.value.find((item: any) => item.label === '厂商').disable = true
      tableHeader.value.find((item: any) => item.label === '交期').disable = true
      tableHeader.value.find((item: any) => item.label === '责任人').disable = true
      tableHeader.value.find((item: any) => item.label === '责任原因').disable = true
      tableHeader.value.find((item: any) => item.label === '请购数量').disable = true
      item.disable = true
    }
    item.dutyRek = {
      selectValue: item.dutyRek,
      options: dutyReks.value.map((Vendor: any, index: any) => {
        if (Vendor === null) return
        return {
          label: Vendor,
          value: Vendor
        }
      })
    }
    item.dutyUser = {
      selectValue: item.dutyUser,
      options: dutyUseres.value.map((Vendor: any, index: any) => {
        if (Vendor === null) return
        return {
          label: Vendor,
          value: Vendor
        }
      })
    }
    item.change = 'Y'
    return item
  })
  total.value = tableDataList.total
  // currentRow()
  summaryData.value[0].num = tableDataList.qtyTotal
  summaryData.value[1].num = tableDataList.purQtyTotal
  clickRow()
}, 500)
onMounted(() => {
  getTableList()
})
watch(
  () =>
    formList.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList()
  }
)
const selectedLists = ref([])
const selectList1 = (selectedList: any) => {
  selectedLists.value = selectedList
}
// 责任原因,责任人 临时保存变量
const dutyReks = ref([])
const dutyUseres = ref([])
const getSelectList = async () => {
  let vendorName = await service.get<any, any>('/back/vendorQuery')
  let { dutyRek, dutyUsers } = await service.get<any, any>('/back/duty/getDutyCondition')
  dutyReks.value = dutyRek
  dutyUseres.value = dutyUsers
  let { molds } = await service.get<any, any>('/back/order/allOrderCondition')
  let vendorNames = formList.value.find(
    (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称'
  ) as any
  let vendorNames2 = formList2.value.find(
    (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '厂商代码 厂商名称'
  ) as any
  let mold = formList.value.find(
    (item: any) => item.type === 'select' && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '底模号'
  ) as any
  // 插入底模
  if (molds && mold) {
    ;(molds as string[]).forEach((item: string, index) => {
      if (item === null || item === '') return
      mold.selectOptions?.push({
        optionKey: index,
        optionValue: item,
        optionLabel: item
      })
    })
  }
  // 插入厂商代码 厂商名称
  if (vendorName && vendorNames) {
    vendorName.forEach((item: any, index: any) => {
      if (item === null) return
      vendorNames.selectOptions?.push({
        optionKey: index,
        optionValue: `${item.vendorNo} ${item.vendorName}`
      })
      vendorNames2.selectOptions?.push({
        optionKey: index,
        optionValue: `${item.vendorNo} ${item.vendorName}`
      })
    })
  }
}
onMounted(() => {
  getSelectList()
})
// 修改
const confirmChange = async (row: any) => {
  row.dutyRek = row.dutyRek.selectValue || ''
  row.dutyUser = row.dutyUser.selectValue || ''
  let res = await LoginWork.post<any, any>('/material/createPcOrderMtlOrder', {
    createFlag: 3,
    list: [row]
  })
  if (res.code === 200) {
    JMessage.success(res.message)
    getTableList()
  } else {
    JMessage.warning(res.message)
  }
}

// 选订单材料（正单）
const tableData2 = ref([])
const tableHeader2 = ref([
  {
    label: '指令',
    prop: 'lotNo',
    width: '160px'
  },
  {
    label: '货号',
    prop: 'style',
    width: '160px'
  },
  {
    label: '物料编码',
    prop: 'mtlNo',
    width: '160px'
  },
  {
    label: '材料颜色',
    prop: 'color',
    width: '160px'
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    width: '160px'
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    width: '160px'
  },
  {
    label: '单位',
    prop: 'mtlUnit',
    width: '160px'
  },
  {
    label: '用量',
    prop: 'usage',
    width: '160px'
  }
])
// 分页器
const currentPage2 = ref(1)
const pageSize2 = ref(40)
const total2 = ref(0)
const handleSizeChange2 = (val: number) => {
  pageSize2.value = val
  getTableList2()
}
const handleCurrentChange2 = (val: number) => {
  currentPage2.value = val
  getTableList2()
}
const isLoading2 = ref(true)
// 获取表数据
const getTableList2 = debounce(async () => {
  isLoading2.value = true
  let tableDataList = await service.post<any, any>('/material/pcOrderMtlRS', {
    lotNo: formList3.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令号'
    )?.inputValue,
    mtlName: formList3.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入材料名称'
    )?.inputValue,
    mtlNo: formList3.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '材料类型')
      ?.selectValue?.split(' ')[0],
    pageNum: currentPage2.value,
    pageSize: pageSize2.value
  })
  isLoading2.value = false
  tableData2.value = tableDataList.list
  total2.value = tableDataList.total
}, 500)
watch(
  () =>
    formList3.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList2()
  }
)
const selectedLists2 = ref([])
const selectList2 = (selectedList: any) => {
  selectedLists2.value = selectedList
}

// 选订单材料（补单）
const tableData3 = ref([])
const tableHeader3 = ref([
  {
    label: '指令',
    prop: 'lotNo',
    width: '160px'
  },
  {
    label: '货号',
    prop: 'style',
    width: '160px'
  },
  {
    label: '物料编码',
    prop: 'mtlNo',
    width: '160px'
  },
  {
    label: '材料颜色',
    prop: 'color',
    width: '160px'
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    width: '160px'
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    width: '160px'
  },
  {
    label: '单位',
    prop: 'mtlUnit',
    width: '160px'
  },
  {
    label: '用量',
    prop: 'usage',
    width: '160px'
  }
])
// 分页器
const currentPage3 = ref(1)
const pageSize3 = ref(40)
const total3 = ref(0)
const handleSizeChange3 = (val: number) => {
  pageSize3.value = val
  getTableList3()
}
const handleCurrentChange3 = (val: number) => {
  currentPage3.value = val
  getTableList3()
}
const isLoading3 = ref(true)
// 获取表数据
const getTableList3 = debounce(async () => {
  isLoading3.value = true
  let tableDataList = await service.post<any, any>('/material/pcOrderMtlSo', {
    lotNo: formList4.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入指令号'
    )?.inputValue,
    mtlName: formList4.value.find(
      (item: any) => item.inputPlaceholder && Jzhcn.Find[item.inputPlaceholder.split('.')[1] as keyof typeof Jzhcn.Find] === '请输入材料名称'
    )?.inputValue,
    mtlNo: formList4.value
      .find((item: any) => item.selectP && Jzhcn.Find[item.selectP.split('.')[1] as keyof typeof Jzhcn.Find] === '材料类型')
      ?.selectValue?.split(' ')[0],
    pageNum: currentPage3.value,
    pageSize: pageSize3.value
  })
  isLoading3.value = false
  tableData3.value = tableDataList.list
  total3.value = tableDataList.total
}, 500)

watch(
  () =>
    formList4.value.map((item: any) => {
      item.selectValue, item.inputValue, item.dateValue, item.checked
    }),
  () => {
    getTableList3()
  }
)
const selectedLists3 = ref([])
const selectList3 = (selectedList: any) => {
  selectedLists3.value = selectedList
}

// 获取材料类型
const getSelectList4 = async () => {
  await selectSomeList(formList3, () => service.get('/back/getMtlType3'))
}
onMounted(async () => {
  getSelectList4()
  await selectSomeList(formList4, () => service.get('/back/getMtlType3'))
})
</script>

<style lang="less" scoped>
:deep(.el-form-item:nth-last-child(6)) {
  .el-select {
    width: 150px;
    height: 28px;
  }
}

// 主体样式
.ProductionDynamicMain {
  width: 100%;
  height: 670px;
  margin-top: 20px;

  .ProductionDynamicMainCard {
    width: 100%;
    height: 750px;
    box-shadow: none;
  }
}

.ProductionDynamicMainCardMain {
  width: 100%;
  height: 600px;
  display: flex;
  margin-left: 20px;
}

.ProductionDynamicMainCardBottom {
  width: 98%;
  height: 110px;
  margin: auto;
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
}

.MainLeftCardH1 {
  font-size: 16px;
  margin: 10px 0 10px 0;
}

.ProductionDynamicMainCardBottomBtn {
  margin-top: 30px;
}

:deep(.elForm .el-form-item__label) {
  color: red !important;
}

.ProductionDynamicMainCardMainLeft {
  width: 100%;
}
</style>
